"use strict";
cc._RF.push(module, 'eff6fDzFUdJCbxGK0qY7jYn', 'TiktokAd');
// scripts/TiktokAd.js

"use strict";

var e = require;
var t = module;
var o = exports;

var _ii,
    nn = void 0 && (void 0).__extends || (_ii = function ii(t, e) {
  return (_ii = Object.setPrototypeOf || {
    __proto__: []
  } instanceof Array && function (t, e) {
    t.__proto__ = e;
  } || function (t, e) {
    for (var o in e) {
      Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o]);
    }
  })(t, e);
}, function (t, e) {
  function o() {
    this.constructor = t;
  }

  _ii(t, e), t.prototype = null === e ? Object.create(e) : (o.prototype = e.prototype, new o());
}),
    rr = void 0 && (void 0).__awaiter || function (t, e, o, i) {
  return new (o || (o = Promise))(function (n, a) {
    function r(t) {
      try {
        l(i.next(t));
      } catch (e) {
        a(e);
      }
    }

    function s(t) {
      try {
        l(i["throw"](t));
      } catch (e) {
        a(e);
      }
    }

    function l(t) {
      var e;
      t.done ? n(t.value) : (e = t.value, e instanceof o ? e : new o(function (t) {
        t(e);
      })).then(r, s);
    }

    l((i = i.apply(t, e || [])).next());
  });
};

var oo = void 0 && (void 0).__decorate || function (e, t, a, n) {
  var i,
      o = arguments.length,
      s = o < 3 ? t : null === n ? n = Object.getOwnPropertyDescriptor(t, a) : n;
  if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) s = Reflect.decorate(e, t, a, n);else for (var r = e.length - 1; r >= 0; r--) {
    (i = e[r]) && (s = (o < 3 ? i(s) : o > 3 ? i(t, a, s) : i(t, a)) || s);
  }
  return o > 3 && s && Object.defineProperty(t, a, s), s;
};

Object.defineProperty(o, "__esModule", {
  value: !0
});
var a = e("Toast"),
    n = e("sdkConfig"),
    i = e("AdInterface"),
    r = cc._decorator,
    s = r.ccclass,
    l = (r.property, function (e) {
  function t() {
    var t = null !== e && e.apply(this, arguments) || this;
    return t.Tiktok_Share_Title = "", t.Tiktok_Name_Title = "", t.Tiktok_Group_ID = "", t.game_version = "102", t.app_test_version = !1, t.videoAd = null, t.loadSucc_Video = null, t.callback_Video = null, t.isShow_Video = !1, t.loadSucc_Banner = !1, t.bannerAd = null, t.loadSucc_SystemBanner = !1, t.hasShowBanner = !1, t.NUM_CheckBannerLoadSucc = 0, t.NUM_MaxCheckBannerLoadSucc = 5, t.interval_updateBanner = null, t.timeout_showSystemBanner = null, t.timeout_checkBannerLoadSucc = null, t.systemIntersAd = null, t.loadSucc_SystemInters = !1, t.NUM_IntersNowIntervalTime = 0, t.NUN_hasVideoShowInters = 0, t.NUM_IntersNowToAddDesktop = 0, t.NUM_hasShowInters = 0, t.NUM_intersNowInterval = 0, t.isPause = !1, t.recorder = tt.getGameRecorderManager(), t.DanceByteMoreGame = null, t;
  }

  var o;
  return nn(t, e), o = t, t.prototype.GameVersion = function (e) {
    this.app_test_version = this.game_version == e;
  }, t.prototype.getGameTestVersion = function () {
    return this.app_test_version;
  }, t.prototype.createAd = function () {
    this.SW_Video && "" != this.ID_Video && this.createVideo(), this.SW_System_Banner && "" != this.ID_System_Banner && this.createSystemBanner(), this.SW_System_Inters && "" != this.ID_System_Inters && this.createSystemInters(), this.NUM_IntersIntervalTime > 0 && this.runIntersInterval(), tt.setKeepScreenOn({
      keepScreenOn: !0,
      success: function success() {
        console.log("屏幕常亮已开启");
      },
      fail: function fail() {
        console.log("setKeepScreenOn调用失败");
      }
    });
  }, t.prototype.createVideo = function () {
    var e = this;
    n["default"].stringHasSpace(this.ID_Video) ? console.log(n["default"].GameName + "********当前渠道视频广告ID中含有空字符串,请检查后台视频广告ID*********************") : (this.videoAd = tt.createRewardedVideoAd({
      adUnitId: this.ID_Video
    }), this.videoAd.onLoad(function () {
      console.log("Tiktok 视频广告加载完成"), e.loadSucc_Video = !0;
    }), this.videoAd.onError(function (t) {
      console.log("Tiktok 视频广告加载失败 ：" + JSON.stringify(t)), e.loadSucc_Video = !1, setTimeout(function () {
        e.videoAd && e.videoAd.load();
      }, 3e4);
    }), this.videoAd.onClose(function (t) {
      setTimeout(function () {
        t.isEnded ? (console.log("Tiktok 激励视频广告完成，发放奖励"), e.callback_Video && (e.callback_Video(!0), e.loadSucc_Video = !1, e.videoAd.load())) : (console.log("Tiktok 激励视频广告取消，不发放奖励"), e.callback_Video && (e.callback_Video(!1), e.loadSucc_Video = !1, e.videoAd.load())), e.isShow_Video = !1;
      }, 500);
    }), this.videoAd.load());
  }, t.prototype.getVideoFlag = function () {
    return this.loadSucc_Video;
  }, t.prototype.showVideo = function (e) {
    var t = this;
    this.isShow_Video ? console.log("视频正在播放中,请勿多次点击！") : (this.isShow_Video = !0, this.callback_Video = e, this.videoAd ? this.videoAd.show().then(function () {
      console.log("Tiktok 激励视频广告显示成功");
    })["catch"](function (e) {
      console.log("Tiktok 激励视频广告组件出现问题", JSON.stringify(e)), t.videoAd.load().then(function () {
        console.log("Tiktok 激励视频广告手动加载成功"), t.videoAd.show()["catch"](function (e) {
          console.log("Tiktok 激励视频广告播放失败", JSON.stringify(e)), t.isShow_Video = !1, t.callback_Video(!1);
        });
      });
    }) : (this.isShow_Video = !1, this.callback_Video(!1)));
  }, t.prototype.createSystemBanner = function () {
    var e = this;
    if (n["default"].stringHasSpace(this.ID_System_Banner)) console.log("当前渠道系统banner广告ID中含有空字符串,请检查后台系统banner广告ID*********************");else {
      var t = tt.getSystemInfoSync().windowWidth,
          o = tt.getSystemInfoSync().windowHeight;
      this.bannerAd = tt.createBannerAd({
        adUnitId: this.ID_System_Banner,
        adIntervals: 30,
        style: {
          left: -1e3,
          top: -1e3
        }
      }), this.bannerAd.onResize(function (a) {
        console.log("Tiktok 系统banner广告重设位置", a, JSON.stringify(a)), e.bannerAd.style.top = o - a.height, e.bannerAd.style.left = (t - a.width) / 2;
      }), this.bannerAd.onLoad(function () {
        console.log("Tiktok 系统banner广告加载成功"), e.loadSucc_SystemBanner = !0, e.hasShowBanner && e.showSystemBanner();
      });
    }
  }, t.prototype.showBanner = function () {
    this.loadSucc_Banner ? this.hasShowBanner ? console.log("已经调用过showBanner,请勿重复调用") : (this.hasShowBanner = !0, this.SW_System_Banner && (this.showSystemBanner(), this.updateSystemBanner())) : this.checkBannerLoadSucc();
  }, t.prototype.hideBanner = function () {
    this.hasShowBanner = !1, this.hideSystemBanner(), this.interval_updateBanner && clearInterval(this.interval_updateBanner), this.timeout_checkBannerLoadSucc && clearTimeout(this.timeout_checkBannerLoadSucc);
  }, t.prototype.checkBannerLoadSucc = function () {
    var e = this;
    if (this.loadSucc_Banner = this.SW_System_Banner && this.loadSucc_SystemBanner, console.log("banner加载成功?", this.loadSucc_Banner, ++this.NUM_CheckBannerLoadSucc), this.timeout_checkBannerLoadSucc && clearTimeout(this.timeout_checkBannerLoadSucc), this.loadSucc_Banner) this.showBanner();else {
      if (this.NUM_CheckBannerLoadSucc >= this.NUM_MaxCheckBannerLoadSucc) return;
      this.timeout_checkBannerLoadSucc = setTimeout(function () {
        e.checkBannerLoadSucc();
      }, 5e3);
    }
  }, t.prototype.showSystemBanner = function () {
    var e = this;
    this.bannerAd ? (console.log("Tiktok showSystemBanner========================"), this.bannerAd.show()) : (this.createSystemBanner(), this.timeout_showSystemBanner = setTimeout(function () {
      e.bannerAd && e.showSystemBanner();
    }, 1e3));
  }, t.prototype.updateSystemBanner = function () {
    var e = this;
    this.interval_updateBanner && clearInterval(this.interval_updateBanner), this.interval_updateBanner = setInterval(function () {
      console.log("Tiktok updateSystemBanner========================"), e.bannerAd.destroy(), e.bannerAd = null, e.createSystemBanner();
    }, 1e3 * this.Control_Banner_Update);
  }, t.prototype.hideSystemBanner = function () {
    this.bannerAd && (console.log("Tiktok hideSystemBanner========================"), this.bannerAd.hide()), this.timeout_showSystemBanner && clearTimeout(this.timeout_showSystemBanner), this.interval_updateBanner && clearInterval(this.interval_updateBanner);
  }, t.prototype.createSystemInters = function () {
    var e = this;
    if (n["default"].stringHasSpace(this.ID_System_Inters)) console.log("当前渠道系统插屏广告ID中含有空字符串,请检查后台系统插屏广告ID*********************");else {
      var t = tt.getSystemInfoSync().appName;
      "Toutiao" == t || "Douyin" == t ? (this.systemIntersAd = tt.createInterstitialAd({
        adUnitId: this.ID_System_Inters
      }), this.systemIntersAd.onLoad(function () {
        console.log("Tiktok 插屏广告加载完成"), e.loadSucc_SystemInters = !0;
      }), this.systemIntersAd.onError(function (t) {
        console.log("Tiktok 插屏加载失败：" + JSON.stringify(t)), e.systemIntersAd && setTimeout(function () {
          e.systemIntersAd && e.systemIntersAd.load();
        }, 3e4);
      }), this.systemIntersAd.onClose(function () {
        console.log("Tiktok 关闭插屏,重新创建插屏广告"), e.NUM_IntersNowIntervalTime = 0, e.systemIntersAd.destroy(), e.createSystemInters(), e.loadSucc_SystemInters = !1, e.systemIntersAd.load();
      }), this.systemIntersAd.load()) : console.log("非抖音/今日头条平台 或抖音平台版本过低 return");
    }
  }, t.prototype.getIntersFlag = function () {
    return this.loadSucc_SystemInters || this.SW_Inters_Desk && this.Inters_Add_Num > 0;
  }, t.prototype.showInters = function () {
    var e = this;

    if (this.getIntersFlag()) {
      if (console.log("Tiktok 展示插屏广告"), this.NUM_hasShowInters++, this.SW_Inters_Desk && this.NUM_hasShowInters <= this.Inters_Add_Num && (console.log("第" + this.Inters_Add_Num + "次插屏变添加桌面", "当前第" + this.NUM_hasShowInters + "次"), this.NUM_hasShowInters == this.Inters_Add_Num)) this.getAddDesktopFlag(function (t) {
        t && (console.log("插屏变添加桌面"), e.addDesktop(function () {}));
      });else {
        if (!this.getErrorControl() && this.Control_Video && this.Control_Inters_To_Video_Switch && this.NUN_hasVideoShowInters > 0) {
          if (console.log("Tiktok 第" + this.Control_Start_Inters_To_Video + "次插屏变视频", "当前第" + this.NUN_hasVideoShowInters + "次"), this.Control_Start_Inters_To_Video > 0 && this.NUN_hasVideoShowInters == this.Control_Start_Inters_To_Video) return console.log("Tiktok 首次插屏变视频"), this.NUN_hasVideoShowInters++, void this.showVideo(function () {});
          if (this.Control_Inters_To_Video > 0 && this.NUN_hasVideoShowInters % this.Control_Inters_To_Video == 0) return console.log("Tiktok 间隔插屏变视频"), this.NUN_hasVideoShowInters++, void this.showVideo(function () {});
        }

        if (this.Control_Inters) {
          if (this.NUM_hasShowInters < this.Control_Start_Num) return void console.log("Tiktok 插屏开始次数未达到", this.NUM_hasShowInters, "目标次数", this.Control_Start_Num);
          if (this.NUM_intersNowInterval < this.Control_Interval_Num) return console.log("Tiktok 插屏间隔次数未达到", this.NUM_intersNowInterval, "目标次数", this.Control_Interval_Num), void this.NUM_intersNowInterval++;
          if (this.NUM_IntersNowIntervalTime < this.Control_Interval_Time) return console.log("Tiktok 插屏间隔时间未达到", this.NUM_IntersNowIntervalTime, "目标时间", this.Control_Interval_Time), void (this.SW_Inters_Desk && this.NUM_IntersNowToAddDesktop < this.Inters_Add_Num && this.getAddDesktopFlag(function (t) {
            t && (e.NUM_IntersNowToAddDesktop++, e.addDesktop(function () {
              console.log("Tiktok 插屏间隔弹桌面");
            }));
          }));
        }

        this.NUM_intersNowInterval = 0, this.Control_Delay_Time > 0 && Math.floor(100 * Math.random()) < this.Control_Delay_Prob ? (console.log("插屏延迟时间(ms):" + this.Control_Delay_Time), setTimeout(function () {
          e.loadSucc_SystemInters && e.showSystemInters();
        }, this.Control_Delay_Time)) : this.loadSucc_SystemInters && this.showSystemInters(), this.NUN_hasVideoShowInters++;
      }
    } else console.log("Tiktok  插屏广告暂未开启************请在后台确认是否开启***************");
  }, t.prototype.showSystemInters = function () {
    this.systemIntersAd && this.loadSucc_SystemInters && (console.log("Tiktok showSystemInters========================"), this.systemIntersAd.show());
  }, t.prototype.runIntersInterval = function () {
    var e = this;
    this.NUM_IntersIntervalTime > 0 && setInterval(function () {
      e.NUM_IntersNowIntervalTime++;
    }, 1e3);
  }, t.prototype.setGroup = function (e) {
    this.AdGroup = e;
  }, t.prototype.hasAddDesktopFunc = function () {
    return !0;
  }, t.prototype.getAddDesktopFlag = function (e) {
    tt.checkShortcut({
      success: function success(t) {
        !t.status.exist || t.status.needUpdate ? (console.log("checkShortcut res:", JSON.stringify(t)), console.log("Tiktok 未创建桌面图标或图标需要更新"), e(!0)) : (console.log("Tiktok 已创建桌面图标"), e(!1));
      },
      fail: function fail(t) {
        console.log("Tiktok 添加桌面图标失败：", JSON.stringify(t.errMsg)), e(!1);
      }
    });
  }, t.prototype.addDesktop = function (e) {
    tt.addShortcut({
      success: function success() {
        console.log("添加桌面成功"), e(!0);
      },
      fail: function fail(t) {
        console.log("添加桌面失败：", JSON.stringify(t)), e(!1);
      }
    });
  }, t.prototype.phoneVibrate = function (e) {
    "long" == e ? tt.vibrateLong({
      success: function success() {},
      fail: function fail(e) {
        console.log("Tiktok vibrateLong调用失败：", JSON.stringify(e));
      }
    }) : "short" == e && tt.vibrateShort({
      success: function success() {},
      fail: function fail(e) {
        console.log("Tiktok vibrateShort调用失败：", JSON.stringify(e));
      }
    });
  }, t.prototype.getGroupFalg = function () {
    var e = tt.getSystemInfoSync().appName;
    return -1 == ["Douyin", "douyin_lite"].indexOf(e) ? (console.log("抖音及抖音极速版 或抖音平台版本过低 return"), !1) : "" != this.Tiktok_Group_ID;
  }, t.prototype.TiktokJoinGroup = function () {
    tt.joinGroup({
      groupid: this.Tiktok_Group_ID,
      sessionFrom: "sessionFrom",
      extraInfo: "extraInfo",
      success: function success(e) {
        console.log("Tiktok 加入群聊成功", e);
      },
      fail: function fail(e) {
        console.log("Tiktok 加入群聊失败", e);
      }
    });
  }, t.prototype.getErrorControl = function () {
    var e = !1;
    return this.getGameTestVersion() || (e = this.adErrorControl()), e;
  }, t.prototype.getCustomErrorControl = function () {
    return !!this.getErrorControl() && this.getCustomError();
  }, t.prototype.StartRecorder = function (e) {
    void 0 === e && (e = 300), n["default"].platform == n.EPlatform.TikTok && (console.log("Tiktok 开始录屏"), this.recorder.start({
      duration: e,
      isMarkOpen: !1
    }));
  }, t.prototype.StopRecorder = function (e) {
    var t = this;
    void 0 === e && (e = 299), n["default"].platform == n.EPlatform.TikTok && (console.log("Tiktok 结束录屏"), this.recorder.onStop(function (a) {
      0 == o.clipIndexList.length ? (console.log("Tiktok  生成完整录屏视频"), t.recorder.clipVideo({
        path: a.videoPath,
        timeRange: [e, 0],
        success: function success(e) {
          console.log("结束录屏-录屏地址：" + e.videoPath), o.RECORDER_PATH = e.videoPath;
        },
        fail: function fail(e) {
          console.error(e);
        }
      })) : (console.log("Tiktok  拼接精彩录屏片段视频"), t.recorder.clipVideo({
        path: a.videoPath,
        clipRange: o.clipIndexList,
        success: function success(e) {
          console.log("结束录屏-精彩录屏片段-录屏地址：" + e.videoPath), o.RECORDER_PATH = e.videoPath;
        },
        fail: function fail(e) {
          console.error(e);
        }
      }));
    }), this.recorder.stop());
  }, t.prototype.ShareVideo = function (e, t) {
    if (n["default"].platform == n.EPlatform.TikTok) {
      var i = o.RECORDER_PATH;
      console.log("Tiktok 分享视频-录屏地址：" + i), "" == this.Tiktok_Share_Title && (this.Tiktok_Share_Title = "小游戏"), "" == i ? a["default"].showNewToast("录屏失败，无法分享，请重新录屏") : tt.shareAppMessage({
        channel: "video",
        title: this.Tiktok_Name_Title,
        desc: this.Tiktok_Share_Title,
        templateId: this.ID_Video_Share,
        extra: {
          videoPath: i,
          videoTopics: [this.Tiktok_Name_Title, this.Tiktok_Share_Title],
          hashtag_list: [this.Tiktok_Name_Title, this.Tiktok_Share_Title],
          video_title: this.Tiktok_Share_Title
        },
        success: function success() {
          e && e();
        },
        fail: function fail() {
          t && t();
        }
      });
    }
  }, t.prototype.RecordClip = function (e, t) {
    console.log("Tiktok 精彩片段"), this.recorder.recordClip({
      timeRange: [e, t],
      success: function success(e) {
        o.clipIndexList.push(e.index), console.log("精彩片段，剪辑记录：", o.clipIndexList, "索引：", e.index);
      }
    });
  }, t.prototype.PauseRecorder = function () {
    console.log("Tiktok 暂停录屏"), n["default"].platform == n.EPlatform.TikTok && (this.isPause = !0, this.recorder.pause());
  }, t.prototype.ResumeRecorder = function () {
    console.log("Tiktok 继续录屏"), n["default"].platform == n.EPlatform.TikTok && this.isPause && (this.isPause = !1, this.recorder.resume());
  }, t.prototype.creatMoreGameButton = function (e, t) {
    if (void 0 === t && (t = 720), n["default"].platform == n.EPlatform.TikTok) {
      if (this.DanceByteMoreGame) return this.DanceByteMoreGame;
      var o = e.convertToWorldSpaceAR(cc.v2()),
          a = o.x / cc.winSize.width,
          i = (cc.winSize.height - o.y) / cc.winSize.height,
          r = a * tt.getSystemInfoSync().screenWidth,
          s = i * tt.getSystemInfoSync().screenHeight,
          l = cc.view.getFrameSize().width / t;
      this.DanceByteMoreGame = tt.createMoreGamesButton({
        type: "image",
        image: "moreGame.png",
        actionType: "box",
        style: {
          left: r,
          top: s,
          width: e.width * l,
          height: e.height * l,
          lineHeight: 40,
          backgroundColor: "",
          textColor: "",
          textAlign: "center",
          fontSize: 16,
          borderRadius: 4,
          borderWidth: 0,
          borderColor: ""
        },
        appLaunchOptions: [{
          appId: "ttXXXXXX",
          query: "foo=bar&baz=qux",
          extraData: {}
        }],
        onNavigateToMiniGame: function onNavigateToMiniGame(e) {
          console.log("跳转其他小游戏", e);
        }
      }), this.DanceByteMoreGame.onTap(function () {
        console.log("点击更多游戏");
      }), this.hideMoreGameButton();
    }
  }, t.prototype.showMoreGameButton = function () {
    this.DanceByteMoreGame && this.DanceByteMoreGame.show();
  }, t.prototype.hideMoreGameButton = function () {
    this.DanceByteMoreGame && this.DanceByteMoreGame.hide();
  }, t.prototype.showFavoriteGuide = function (e, t, o) {
    console.log("Tiktok showFavoriteGuide===============", e, t, o), tt.showFavoriteGuide({
      type: e,
      content: t,
      position: o,
      success: function success() {
        console.log("引导组件展示成功");
      },
      fail: function fail(e) {
        console.log("引导组件展示失败:" + JSON.stringify(e));
      }
    });
  }, t.RECORDER_PATH = "", t.clipIndexList = [], o = oo([s], t);
}(i["default"]));
o["default"] = l;

cc._RF.pop();